$(function(){		
	
	// 中文字两个字节
	jQuery.validator.addMethod("byteRangeLength", function(value, element, param) {
		var length = value.length;
		for(var i = 0; i < value.length; i++){
			if(value.charCodeAt(i) > 127){
				length++;
			}
		}
		return this.optional(element) || ( length >= param[0] && length <= param[1] );
	},"<font color=red><br/>请确保输入的值在3-15个字节之间(一个中文字算2个字节)</font>");
	
	// 身份证号码验证
	jQuery.validator.addMethod("isIdCardNo", function(value, element) {
	return this.optional(element) ||isIdCardNo(value);
	}, "<font color=red><br/>请正确输入您的身份证号码</font>");				
	
	// 手机号码验证
	jQuery.validator.addMethod("isMobile", function(value, element) {
	var length = value.length;
	var mobile = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
	return this.optional(element) || (length == 11 && mobile.test(value));
	}, "<font color=red><br/>请正确填写您的手机号码</font>");

});

//获取左侧的导航树
function getMenuLeft(firstId,firstName,url,lastId){
	var strHtml='<li><a style="padding:10px;" aria-expanded="true" href="'+url+'">'+
					'<span class="fa fa-home"></span>'+
					'<span class="sidebar-nav-item">'+firstName+'</span>'+								
					'</a></li>';		            
    $("#menuLeft").append(strHtml);	
    
	//获取子 菜单 
	$.ajax({  
		type: "POST",  
        url: $ctx+'SiteIndex/getMenuTree.json', 
	    data:{  
	    	parentID:firstId,
	    	issue:1
	    },  		    	     
	    async: false, //同步
	    cache:false,  
	    dataType:'json',  
	    success:function(data) { 
	    	if(data!=null && data.length>0){	
	    		
	    		$.each(data,function(idx,obj){
	    			var urlNew='';
	    			if(obj.url!='' && (obj.url).indexOf('http')==-1){
	    				urlNew=$ctx+obj.url;	    				
	    			}else{
	    				urlNew=obj.url;
	    			}
		            var addHtml='<li id="nav'+obj.id+'"><a aria-expanded="false" href="'+urlNew+'">'+obj.menuName;
		            
		            var addChild=childMenuHtml(obj);
            		if(addChild!=''){
            			addHtml+='<span class="glyphicon arrow"></span></a>'+addChild
            		}else{
            			addHtml+='</a>'+addChild
            		}
            		addHtml+='</li>';				            		
		            $("#menuLeft").append(addHtml);						           
			       
	    		});
	    	}
	    },  
	     error : function() {  
	          alert("异常！");  
	     } 
	});
	
	// 默认	
	$("#nav"+lastId).addClass("nowActive");	
	   
}

//获取左侧 菜单 -- 递归 孩子节点
function childMenuHtml(obj){
	var childrenHtml='';
	 if(obj.hasOwnProperty("children")){		 
        	childrenHtml='<ul aria-expanded="false" class="collapse">';        	
        	$.each(obj.children,function(i,item){//循环孩子节点	
        		// 再次判断 是否有孩子节点
        		childrenHtml+='<li><a href="'+obj.url+'">'+item.menuName;        		
        		var subhtml=childMenuHtml(item);//递归        		
        		if(subhtml!=''){
        			childrenHtml+='<span class="fa plus-times"></span></a>'+subhtml
        		}else{
        			childrenHtml+='</a>'+subhtml
        		}		            		
        		childrenHtml+='</li>';        		
        	});
        	childrenHtml+='</ul>';
     }			 
	 return childrenHtml;
}


//隔行变色	& 鼠标滑过变色		
function trRecolor(){ 	
	
	var Ptr=document.getElementsByTagName("tr");				
	for (i=1;i<Ptr.length+1;i++) {
		Ptr[i-1].className = (i%2>0)?"t1":"t2";
	}			
	for(var i=0;i<Ptr.length;i++) {
		Ptr[i].onmouseover=function(){
			this.tmpClass=this.className;
			this.className = "t3";
		};
	
		Ptr[i].onmouseout=function(){
			this.className=this.tmpClass;
		};
	}
}

//验证码
function changeImage() { 
    var img = document.getElementById("validatImg"); 
    img.src =$ctx+"webcode.htm?date=" + new Date();//加上一个随机数,防止重复 
    $("#validatImg").show(); 
}


//身份证号码的验证规则
function isIdCardNo(num){
 //if (isNaN(num)) {alert("输入的不是数字！"); return false;} 
	var len = num.length, re; 
	if (len == 15){
		re = new RegExp(/^(\d{6})()?(\d{2})(\d{2})(\d{2})(\d{2})(\w)$/); 
	}else if (len == 18) {
		re = new RegExp(/^(\d{6})()?(\d{4})(\d{2})(\d{2})(\d{3})(\w)$/); 
	}else {	           	
    	return false;
	}
	var a = num.match(re); 
	if (a != null){
		if (len==15){
			var D = new Date("19"+a[3]+"/"+a[4]+"/"+a[5]); 
			var B = D.getYear()==a[3]&&(D.getMonth()+1)==a[4]&&D.getDate()==a[5]; 
		}else{
			var D = new Date(a[3]+"/"+a[4]+"/"+a[5]); 
			var B = D.getFullYear()==a[3]&&(D.getMonth()+1)==a[4]&&D.getDate()==a[5]; 
		}
		if (!B) {	             
      		return false;
		} 
	}
	if(!re.test(num)){	          	
    	return false;
	}
	return true; 
}













